<template>

  <div class="app-container">


    <el-form :inline="true" :model="queryForm" class="demo-form-inline">
      <el-form-item label="城市">
        <el-input v-model="queryForm.name" placeholder="请输入城市名称." style="width: 18.75rem;" />
      </el-form-item>
      <el-form-item label="代码">
        <el-input v-model="queryForm.code" placeholder="请输入城市代码." style="width: 18.75rem;" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search"  size="mini" :loading="loading" @click="onQuerySubmit">查询</el-button>
        <el-button type="info" icon="el-icon-refresh"  size="mini" :loading="loading" @click="onReset">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table
      :data="tableData"
      border
      empty-text="暂无数据."
      style="width: 100%">
      <el-table-column
        prop="cityName"
        label="城市"
        >
      </el-table-column>
      <el-table-column
        prop="cityCode"
        label="代码"
        >
      </el-table-column>
      <el-table-column
        prop="weather"
        label="天气"
        >
      </el-table-column>
      <el-table-column
        prop="temp"
        label="温度"
        >
      </el-table-column>
      <el-table-column
        prop="wd"
        label="风向"
        >
      </el-table-column>
      <el-table-column
        prop="ws"
        label="风力等级"
        >
      </el-table-column>

      <el-table-column
        prop="aqi"
        label="空气质量指数"
        >
      </el-table-column>

      <el-table-column
        prop="time"
        label="实况">
      </el-table-column>
      <el-table-column
        prop="sd"
        label="相对湿度">
      </el-table-column>

      <el-table-column prop="updateTime" label="更新时间" >
        <template slot-scope="scope">
          <span>{{ scope.row.updateTime | dateFormat}}</span>
        </template>
      </el-table-column>

    </el-table>

    <el-row>
      <el-col :span="24">
        <div align="right" style="margin-top: 0.3125rem;">
          <el-pagination background layout="prev, pager, next" :current-page="page.cur" :page-size="page.limit" :total="page.total" @current-change="handleCurrentChange" />
        </div>
      </el-col>
    </el-row>

    <!--编辑框-->
    <info-dialog
      v-if="editDialog.visible"
      :properties="editDialog"
      @closed="close"
      @refresh="load"
    />

  </div>
</template>

<script>
  import InfoDialog from './components/InfoDialog.vue'
  import {
    hasPermission
  } from '@/utils/permission'
  import {
    findOftenList
  } from '@/api/weather/often'
  import {
    isOk
  } from '@/utils/request'
  export default {
    name:'Often',
    components: {
      InfoDialog
    },
    data() {
      return {
        loading:false,
        queryForm: {
          name: undefined,
          copde: '',
        },
        page: {
          cur: 1,
          limit: 50,
          total: 0
        },
        tableData: [],
        editDialog: {
          visible: false,
          type: '0',
          data: {}
        }
      }
    },
    created() {
      this.load();
    },
    methods: {
      indexMethod(index) {
        return index +1;
      },
      onQuerySubmit(event) {
        this.load()
      },
      onReset(event) {
        this.queryForm.keywords=undefined;
        this.queryForm.status='';
        this.load()
      },
      load(){
        this.loading=true
        findOftenList({
          cur: this.page.cur,
          limit: this.page.limit,
          keywords: this.queryForm.keywords,
          orgId: this.queryForm.orgId,
          status: this.queryForm.status
        }).then(rsp => {
          if(isOk(rsp)){
            const _data = rsp.data.list
            this.page.total = rsp.data.totalRow
            this.tableData = _data
            this.loading = false
          }
        }).catch(err => {
          console.log(err);
        })
        .finally(() => {
          this.loading = false
        })
      },
      close: function(e) {
        this.editDialog.visible = false
        this.editDialog.data = {}
        this.load()
      },
      handleCurrentChange(cur) {
        this.page.cur = cur
        this.load()
      },
    }
  }
</script>
